import { createHashRouter, createBrowserRouter } from "react-router";
import Home from '@/pages/Home/index.tsx';
import Employee from '@/pages/Employee/index.tsx';
import Information from '@/pages/Employee/Information/index.tsx';
import NotFound from '@/pages/error/404.tsx';
import EchartsTable from '@/pages/EchartsTable/index.tsx';
import EchartsProcess from '@/pages/EchartsProcess/index.tsx'

import AppLayout from '@/layout/index.tsx';
import Echarts from '@/layout/echarts.tsx';

const routes = [
  {
    path: '/',
    Component: AppLayout,
    children: [
      {
        path: '/',
        Component: Home,
        handle: { title: '智慧工作台' },
      },
      {
        path: '/home',
        Component: Home,
        handle: { title: '智慧工作台' },
      },
      {
        path: '/employee',
        Component: Employee,
        handle: { title: '数字员工管理' },
      },
      {
        path: '/employee/information',
        Component: Information,
        handle: { title: '数字员工管理' },
      },
    ],
  },
  {
    path: '/echarts_table',
    Component: Echarts,
    children: [
      {
        path: '',
        Component: EchartsTable,
        handle: { title: 'Echarts_table' },
      },
      {
        path: 'echarts_process',
        Component: EchartsProcess,
        handle: { title: 'echarts_process' },
      }
    ],
  },
  {
    path: '*',
    Component: NotFound,
  },
];

function createRouter() {
  const mode = import.meta.env.VITE_ROUTER_MODE || 'hash';

  if (mode === 'history') {
    return createBrowserRouter(routes);
  } else {
    return createHashRouter(routes);
  }
}

const router = createRouter();

export default router;
